<template>
    <el-card class="box-card">
      <template #header>
        <div class="card-header">
          <span>通知中心</span>
          <el-button style="float: right; padding: 3px 0" type="text" @click="markAllAsRead">全部标记为已读</el-button>
        </div>
      </template>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="未读通知" name="unread">
          <el-timeline>
            <el-timeline-item v-for="(notification, index) in unreadNotifications" :key="index" :timestamp="notification.timestamp">
              <el-card>
                <h4>{{ notification.title }}</h4>
                <p>{{ notification.content }}</p>
                <el-button type="text" @click="markAsRead(notification.id)">标记为已读</el-button>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </el-tab-pane>
        <el-tab-pane label="已读通知" name="read">
          <el-timeline>
            <el-timeline-item v-for="(notification, index) in readNotifications" :key="index" :timestamp="notification.timestamp">
              <el-card>
                <h4>{{ notification.title }}</h4>
                <p>{{ notification.content }}</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </template>
  
  <script>
  export default {
    data() {
      return {
        activeName: 'unread',
        notifications: [
          { id: 1, title: '新订单通知', content: '您有一个新的订单！', timestamp: '2023-10-01 10:00', read: false },
          { id: 2, title: '系统维护通知', content: '系统将于今晚进行维护，请提前做好准备。', timestamp: '2023-10-02 14:00', read: false },
          { id: 3, title: '活动邀请', content: '欢迎参加我们的周年庆活动！', timestamp: '2023-10-03 12:00', read: true }
        ]
      };
    },
    computed: {
      unreadNotifications() {
        return this.notifications.filter(notification => !notification.read);
      },
      readNotifications() {
        return this.notifications.filter(notification => notification.read);
      }
    },
    methods: {
      markAsRead(id) {
        const notification = this.notifications.find(notification => notification.id === id);
        if (notification) {
          notification.read = true;
        }
      },
      markAllAsRead() {
        this.notifications.forEach(notification => {
          notification.read = true;
        });
      },
      handleClick(tab) {
        this.activeName = tab.name;
      }
    }
  };
  </script>
  
  <style scoped>
  .box-card {
    width: 70%;
    height: auto;
    margin-left: 14%;
    background-color: rgba(205, 171, 206, 0.089);

  }
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  </style>
  